home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 7 / PC World Interactive 7.iso / bb2000 / files / BlueGame.dxr / 00177_policeScript.ls < prev    next >
Encoding:
Text File  |  1998-02-20  |  6.8 KB  |  259 lines

  1. property ancestor, bluesCAR, carYpos, carXpos, CAR, carIsDrivingHori, carIsDrivingVert, myDirection, myCounter, myRatio, animCounter, historyList, goingInReverse
  2. global myGridArray, gCarObj, gGamesMasterObj, jailBubList, BLOCKWIDTH, BLOCKHEIGHT, POLICESPRITES
  3.  
  4. on new me
  5.   set ancestor to new(script "carScript")
  6.   return me
  7. end
  8.  
  9. on init me, xPos, yPos, ratioNum
  10.   set carXpos to xPos
  11.   set carYpos to yPos
  12.   set CAR to findSpace(me)
  13.   set carIsDrivingHori to 0
  14.   set carIsDrivingVert to 0
  15.   set myDirection to 0
  16.   set myCounter to 0
  17.   set animCounter to 0
  18.   set goingInReverse to 0
  19.   set historyList to []
  20.   set myRatio to ratioNum
  21.   set bluesCAR to the CAR of gCarObj
  22.   appear(me, "po1N.PCT")
  23. end
  24.  
  25. on findSpace me
  26.   repeat with x = POLICESPRITES to POLICESPRITES + 4
  27.     if the memberNum of sprite x = 0 then
  28.       return x
  29.       exit repeat
  30.     end if
  31.   end repeat
  32.   return 0
  33. end
  34.  
  35. on mainRoutine me
  36.   animateCar(me)
  37.   if carIsDrivingHori then
  38.     set myCounter to myCounter + 1
  39.     if myCounter > (BLOCKWIDTH / myRatio) then
  40.       set the carIsDrivingHori of me to 0
  41.     else
  42.       set the locH of sprite CAR to the locH of sprite CAR + (myDirection * myRatio)
  43.     end if
  44.   else
  45.     if the carIsDrivingVert of me then
  46.       set myCounter to myCounter + 1
  47.       if myCounter > (BLOCKHEIGHT / myRatio) then
  48.         set the carIsDrivingVert of me to 0
  49.       else
  50.         set the locV of sprite CAR to the locV of sprite CAR + (myDirection * myRatio)
  51.       end if
  52.     else
  53.       if not goingInReverse then
  54.         findBlues(me)
  55.       else
  56.         set myRatio to 20
  57.         returnToBase(me)
  58.       end if
  59.     end if
  60.   end if
  61. end
  62.  
  63. on animateCar me
  64.   set animCounter to animCounter + 1
  65.   if animCounter > 3 then
  66.     set animCounter to 1
  67.   end if
  68.   changeCar(me, "po" & animCounter)
  69. end
  70.  
  71. on findBlues me
  72.   set blueH to the locH of sprite bluesCAR
  73.   set blueV to the locV of sprite bluesCAR
  74.   set carH to the locH of sprite CAR
  75.   set carV to the locV of sprite CAR
  76.   if (blueV < carV) and (blueH < carH) then
  77.     pickRoute(me, [4, 1])
  78.   else
  79.     if (blueV < carV) and (blueH > carH) then
  80.       pickRoute(me, [1, 2])
  81.     else
  82.       if (blueV > carV) and (blueH > carH) then
  83.         pickRoute(me, [2, 3])
  84.       else
  85.         if (blueV > carV) and (blueH < carH) then
  86.           pickRoute(me, [3, 4])
  87.         else
  88.           if blueV < carV then
  89.             goRoute(me, 1)
  90.           else
  91.             if blueH > carH then
  92.               goRoute(me, 2)
  93.             else
  94.               if blueV > carV then
  95.                 goRoute(me, 3)
  96.               else
  97.                 if blueH < carH then
  98.                   goRoute(me, 4)
  99.                 end if
  100.               end if
  101.             end if
  102.           end if
  103.         end if
  104.       end if
  105.     end if
  106.   end if
  107. end
  108.  
  109. on returnToBase me
  110.   if historyList <> [] then
  111.     set nextDirection to getAt(historyList, count(historyList))
  112.     deleteAt(historyList, count(historyList))
  113.     case nextDirection of
  114.       1:
  115.         set the member of sprite CAR to member ("po" & animCounter & "N.PCT")
  116.         moveVertical(me, -1)
  117.       2:
  118.         set the member of sprite CAR to member ("po" & animCounter & "E.PCT")
  119.         moveHorizontal(me, 1)
  120.       3:
  121.         set the member of sprite CAR to member ("po" & animCounter & "S.PCT")
  122.         moveVertical(me, 1)
  123.       4:
  124.         set the member of sprite CAR to member ("po" & animCounter & "W.PCT")
  125.         moveHorizontal(me, -1)
  126.     end case
  127.   else
  128.     set the policeCounter of gGamesMasterObj to the policeCounter of gGamesMasterObj - 1
  129.     destroy(me)
  130.   end if
  131. end
  132.  
  133. on pickRoute me, dirList
  134.   set oldList to value(string(dirList))
  135.   set firstDir to getAt(dirList, random(count(dirList)))
  136.   deleteAt(dirList, getOne(dirList, firstDir))
  137.   set secondDir to getAt(dirList, 1)
  138.   if carCanGoThatWay(me, firstDir) then
  139.     whichWay(me, firstDir)
  140.   else
  141.     if carCanGoThatWay(me, secondDir) then
  142.       whichWay(me, secondDir)
  143.     else
  144.       alternativeRoute(me, oldList)
  145.     end if
  146.   end if
  147. end
  148.  
  149. on goRoute me, dir
  150.   if carCanGoThatWay(me, dir) then
  151.     whichWay(me, dir)
  152.   else
  153.     alternativeRoute(me, dir)
  154.   end if
  155. end
  156.  
  157. on alternativeRoute me, unknownType
  158.   set bigList to [1, 2, 3, 4]
  159.   if listp(unknownType) then
  160.     repeat with i = 1 to count(unknownType)
  161.       set tempInt to getAt(unknownType, i)
  162.       deleteAt(bigList, getOne(bigList, tempInt))
  163.     end repeat
  164.   else
  165.     deleteAt(bigList, getOne(bigList, unknownType))
  166.   end if
  167.   goRoute(me, getAt(bigList, random(count(bigList))))
  168. end
  169.  
  170. on carCanGoThatWay me, indexNum
  171.   set myOptions to getIndex(me, myGridArray, carYpos, carXpos)
  172.   if getAt(myOptions, indexNum) = 1 then
  173.     return 1
  174.   end if
  175.   return 0
  176. end
  177.  
  178. on whichWay me, indexNum
  179.   case indexNum of
  180.     1:
  181.       set carYpos to carYpos - 1
  182.       if nextSpaceFree(me) then
  183.         set the member of sprite CAR to member ("po" & animCounter & "N.PCT")
  184.         moveVertical(me, -1)
  185.         append(historyList, 3)
  186.       else
  187.         set carYpos to carYpos + 1
  188.       end if
  189.     2:
  190.       set carXpos to carXpos + 1
  191.       if nextSpaceFree(me) then
  192.         set the member of sprite CAR to member ("po" & animCounter & "E.PCT")
  193.         moveHorizontal(me, 1)
  194.         append(historyList, 4)
  195.       else
  196.         set carXpos to carXpos - 1
  197.       end if
  198.     3:
  199.       set carYpos to carYpos + 1
  200.       if nextSpaceFree(me) then
  201.         set the member of sprite CAR to member ("po" & animCounter & "S.PCT")
  202.         moveVertical(me, 1)
  203.         append(historyList, 1)
  204.       else
  205.         set carYpos to carYpos - 1
  206.       end if
  207.     4:
  208.       set carXpos to carXpos - 1
  209.       if nextSpaceFree(me) then
  210.         set the member of sprite CAR to member ("po" & animCounter & "W.PCT")
  211.         moveHorizontal(me, -1)
  212.         append(historyList, 2)
  213.       else
  214.         set carXpos to carXpos + 1
  215.       end if
  216.   end case
  217. end
  218.  
  219. on nextSpaceFree me
  220.   repeat with i = 2 to count(the actorList)
  221.     set myObject to getAt(the actorList, i)
  222.     if the CAR of myObject <> CAR then
  223.       if (the carXpos of myObject = carXpos) and (the carYpos of myObject = carYpos) then
  224.         if the CAR of myObject = the CAR of gCarObj then
  225.           set whichMember to getAt(["dead", "last", "first"], the bluesWarnings of gGamesMasterObj)
  226.           createBubble(me, "bubbleScript", jailBubList, whichMember)
  227.           setCaught(gGamesMasterObj)
  228.         end if
  229.         return 0
  230.         exit repeat
  231.       end if
  232.     end if
  233.   end repeat
  234.   return 1
  235. end
  236.  
  237. on createBubble me, whichScript, whichList, whichMember
  238.   if whichList = [] then
  239.     set horPos to the locH of sprite the CAR of me
  240.     set verPos to the locV of sprite the CAR of me
  241.     if horPos < 280 then
  242.       set xPos to horPos + 15
  243.       set hCode to 4
  244.     else
  245.       set xPos to horPos - 15
  246.       set hCode to 2
  247.     end if
  248.     if verPos < 180 then
  249.       set yPos to verPos + 15
  250.       set vCode to 1
  251.     else
  252.       set yPos to verPos - 15
  253.       set vCode to 3
  254.     end if
  255.     set bubbleObj to new(script whichScript)
  256.     appear(bubbleObj, xPos, yPos, whichMember & vCode & hCode & ".PCT", whichList)
  257.   end if
  258. end
  259.